package servlet;

import entity.Finance;
import entity.Schedule;
import service.FinanceService;
import service.ScheduleService;
import service.UserService;
import service.impl.FinanceServiceImpl;
import service.impl.ScheduleServiceImpl;
import service.impl.UserServiceImpl;
import util.ScannerUtils;

import java.util.ArrayList;

public class UserSchedule {
    UserService userService = new UserServiceImpl();
    ScheduleService scheduleService=new ScheduleServiceImpl();
    public void userList(String idNumber) throws Exception{
        System.out.println("日程管理：");
        System.out.println("请选择：");
        System.out.println("1.查看日程安排");
        System.out.println("2.添加日程");
        String choice = ScannerUtils.scannerUtil();
        if(choice.equals("1")){
            listSchedule(idNumber);
        }else if(choice.equals("2")){
            addSchedule(idNumber,null);
        }
    }
    public void listSchedule(String idNumber) throws Exception{
        ArrayList<Schedule> list = scheduleService.findSchedule(idNumber);

        for(int i = 0; i < list.size(); i++){
            System.out.println(list.get(i).getSchedule());
        }
        UserSchedule userSchedule = new UserSchedule();
        userSchedule.userList(idNumber);
    }
    public void addSchedule(String idNumber, String schedule) throws Exception{
        if(schedule == null){
            System.out.println("请输入新的日程安排");
            schedule = ScannerUtils.scannerUtil();
            scheduleService.insert(idNumber,schedule);
            UserSchedule userSchedule = new UserSchedule();
            userSchedule.userList(idNumber);
        }else{
            scheduleService.insert(idNumber,schedule);
        }
    }

}
